package com.cci.kangdao.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cci.kangdao.service.CourseTrainingService;
import com.cci.kangdao.utilTool.ParameterTool;
/**
 * @Description: 课程相关信息业务
 * @Company: CTY
 * @author 米艳春
 * @date 2018-01-18
 * @version 1.0
 */
@Controller
public class CourseTraining {
	private Logger log = Logger.getLogger(this.getClass().getName());

	@Autowired
	private CourseTrainingService courseTrainingService;

	/**
	 * App获取本人课程接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/getMyCourseTraining.aspx")
	public ModelAndView getMyCourseTraining(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return courseTrainingService.getMyCourseTraining(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}

	/**
	 * App获取学习营课程接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/getCourseTraining.aspx")
	public ModelAndView getCourseTraining(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return courseTrainingService.getCourseTraining(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * App搜索课程接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/searchCourseTraining.aspx")
	public ModelAndView searchCourseTraining(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return courseTrainingService.searchCourseTraining(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 *  App获取课程详细接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/getCourseDetail.aspx")
	public ModelAndView getCourseDetail(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return courseTrainingService.getCourseDetail(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * App上传学习课程接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/uploadCourseDetail.aspx")
	public ModelAndView uploadCourseDetail(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return courseTrainingService.uploadCourseDetail(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 *  App获取课程考试接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/getCourseExam.aspx")
	public ModelAndView getCourseExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return courseTrainingService.getCourseExam(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * App上传考试课题详细接口 
	 * @param map
	 * @return
	 */
	@RequestMapping("/uploadCourseExam.aspx")
	public ModelAndView uploadCourseExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return courseTrainingService.uploadCourseExam(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * App查询课程考试结果接口 
	 * @param map
	 * @return
	 */
	@RequestMapping("/getCourseExamDetail.aspx")
	public ModelAndView getCourseExamDetail(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);			
			map.put("response", response);
			return courseTrainingService.getCourseExamDetail(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}

	/**
	 * App用户修改课件状态接口 
	 * @param map
	 * @return
	 */
	@RequestMapping("/updateCourseTraining.aspx")
	public ModelAndView updateCourseTraining(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return courseTrainingService.updateCourseTraining(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * 获取课程是否已加入学习
	 * @param map
	 * @return
	 */
	@RequestMapping("/getCourseStudyStatus.aspx")
	public ModelAndView getCourseStudyStatus(HttpServletRequest request,
											 HttpServletResponse response) throws Exception {

		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return courseTrainingService.getCourseStudyStatus(map);
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	/**
	 * 更新播放数量
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/updatePlaybackVolume.aspx")
	public ModelAndView updatePlaybackVolume(HttpServletRequest request,
											 HttpServletResponse response) throws Exception {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return courseTrainingService.updatePlaybackVolume(map);
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
}
